<!--
  信息卡片组件
  通用的信息展示卡片，支持标题、描述、元数据、标签等，可配置为可点击的链接
-->
<template>
  <component
    :is="rootComponent"
    class="info-card"
    :class="{ highlight, 'is-clickable': isClickable }"
    v-bind="rootProps"
  >
    <header class="card-header">
      <div class="title-group">
        <div v-if="icon" class="title-icon">
          <slot name="icon">
            <span class="icon-placeholder">{{ icon }}</span>
          </slot>
        </div>
        <div class="title-text">
          <h3 class="card-title">{{ title }}</h3>
          <slot name="subtitle" />
        </div>
      </div>
      <slot name="actions" />
    </header>
    <p v-if="description" class="card-description">{{ description }}</p>
    <ul v-if="metaItems.length" class="meta-list">
      <li v-for="item in metaItems" :key="item.label" class="meta-item">
        <span class="meta-label">{{ item.label }}</span>
        <span class="meta-value">{{ item.value }}</span>
      </li>
    </ul>
    <div v-if="tags.length" class="tag-group">
      <span v-for="tag in tags" :key="tag" class="tag">{{ tag }}</span>
    </div>
    <footer v-if="$slots.footer" class="card-footer">
      <slot name="footer" />
    </footer>
  </component>
</template>

<script setup>
import { computed } from 'vue'
import { RouterLink } from 'vue-router'

const props = defineProps({
  title: {
    type: String,
    required: true,
  },
  description: {
    type: String,
    default: '',
  },
  meta: {
    type: Array,
    default: () => [],
  },
  tags: {
    type: Array,
    default: () => [],
  },
  highlight: {
    type: Boolean,
    default: false,
  },
  icon: {
    type: String,
    default: '',
  },
  to: {
    type: [String, Object],
    default: null,
  },
  clickable: {
    type: Boolean,
    default: false,
  },
})

const metaItems = computed(() =>
  props.meta
    .filter((item) => item && item.label && item.value !== undefined && item.value !== null)
    .map((item) => ({
      label: item.label,
      value: item.value,
    })),
)

const tags = computed(() => props.tags.filter(Boolean))

const rootComponent = computed(() => (props.to ? RouterLink : 'article'))
const rootProps = computed(() => (props.to ? { to: props.to } : {}))
const isClickable = computed(() => Boolean(props.to) || props.clickable)
</script>

<style scoped>
.info-card {
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  padding: 24px 26px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
  text-decoration: none;
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    background 0.25s ease;
}

.info-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(64, 158, 255, 0.08), rgba(236, 245, 255, 0));
  opacity: 0;
  transition: opacity 0.3s ease;
}

.info-card.highlight {
  border-color: rgba(64, 158, 255, 0.45);
  box-shadow: 0 14px 32px rgba(64, 158, 255, 0.18);
}

.info-card:hover {
  transform: translateY(-4px);
  border-color: rgba(64, 158, 255, 0.38);
  box-shadow: 0 18px 36px rgba(64, 158, 255, 0.2);
  background: linear-gradient(135deg, rgba(255, 255, 255, 1), rgba(236, 245, 255, 0.6));
}

.info-card.is-clickable {
  cursor: pointer;
}

.info-card:hover::before {
  opacity: 1;
}

.info-card * {
  text-decoration: none;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(64, 158, 255, 0.15), rgba(103, 194, 58, 0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #409eff;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}

.title-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1f2d3d;
  line-height: 1.4;
  text-decoration: none;
}

.card-description {
  margin: 0;
  color: #606266;
  line-height: 1.6;
  font-size: 14px;
  text-decoration: none;
}

.meta-list {
  list-style: none;
  padding: 10px 0 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 20px;
}

.meta-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  color: #4a5568;
  text-decoration: none;
}

.meta-label {
  font-weight: 500;
  color: #6b7280;
  font-size: 13px;
}

.meta-value {
  font-weight: 600;
  color: #1f2d3d;
  word-break: break-word;
}

.meta-item:last-child {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .meta-list {
    grid-template-columns: 1fr;
  }

  .meta-item {
    justify-content: space-between;
  }
}

.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(64, 158, 255, 0.12);
  color: #2f6fd3;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease;
}

.tag:hover {
  background: rgba(64, 158, 255, 0.2);
  color: #1f4fa3;
}

.card-footer {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
</style>

